//
//  UIViewController+ExExVisible.m
//  OC-Example
//
//  Created by lcj on 2020/11/3.
//  Copyright © 2020 apang.men. All rights reserved.
//

#import "UIViewController+ExExVisible.h"

@implementation UIViewController (ExExVisible)
+ (UIViewController *)ap_visibleViewController {
    return [UIViewController getVisibleViewControllerFromVC:[[[[UIApplication sharedApplication] delegate] window] rootViewController]];
}

+ (UIViewController *)getVisibleViewControllerFromVC:(UIViewController *)vc {
    if ([vc isKindOfClass:[UINavigationController class]]) {
        return [UIViewController getVisibleViewControllerFromVC:[((UINavigationController *)vc) visibleViewController]];
    }else if ([vc isKindOfClass:[UITabBarController class]]){
        return [UIViewController getVisibleViewControllerFromVC:((UITabBarController *)vc).selectedViewController];
    }else {
        if (vc.presentedViewController) {
            return [UIViewController getVisibleViewControllerFromVC:vc.presentedViewController];
        }else{
            return vc;
        }
    }
}
@end
